package com.such.kit.datastructure.graph.exception;

import java.util.List;
import com.such.kit.datastructure.graph.bean.Vertex;
import com.such.kit.validate.ValidateCommons;

public class LoopException extends RuntimeException {

	private static final long serialVersionUID = -7261285222515828053L;
	private String message;

	public String getMessage() {
		return this.message;
	}

	public <T> LoopException(List<Vertex<T>> loopVertices) {
		super();
		StringBuffer message = new StringBuffer();
		message.append("图中有顶点形成了环，参考信息：[");
		if (ValidateCommons.isNotEmpty(loopVertices)) {
			int index = 0;
			for (Vertex<T> vertex : loopVertices) {
				if (index > 0) {
					message.append(", ");
				}
				message.append(vertex.getLabel().toString());
				index++;
			}
		}
		message.append("]");
		this.message = message.toString();
	}

}
